package Text3;

public class Main {
    public static void func1(int[] arr) {
        int cur = 0, dest = -1;
        while (cur < arr.length) {
            if (arr[cur] != 0) {
                swap(arr, dest + 1, cur);
                dest++;
            }
            cur++;
        }
    }

    public static void swap(int[] arr, int x, int y) {
        int tmp = arr[x];
        arr[x] = arr[y];
        arr[y] = tmp;
    }


    public void duplicateZeros(int[] arr) {
        int dest = -1, cur = 0, n = arr.length;
        while (cur < n) {
            if (arr[cur] != 0) {
                dest++;
            } else {
                dest += 2;
            }
            if (dest >= n - 1) {
                break;
            }
            cur++;
        }
        if (dest > n - 1) {
            arr[arr.length - 1] = 0;
            cur--;
            dest -= 2;
        }
        while (cur >= 0) {
            if (arr[cur] != 0) {
                arr[dest--] = arr[cur--];
            } else {
                arr[dest--] = 0;
                arr[dest--] = 0;
                cur--;
            }
        }

    }
}
